package com.lipaluma.field.mapper.single.impl;

import java.lang.reflect.Field;

import com.lipaluma.annotations.validations.Validate;
import com.lipaluma.context.Context;
import com.lipaluma.field.mapper.mapping.MappingInfo;
import com.lipaluma.field.mapper.mapping.MappingOptions;
import com.lipaluma.field.mapper.single.AbstractStandardSingleFieldMapper;
import com.lipaluma.field.validator.ChainValidator;
import com.lipaluma.field.validator.ValidationBasicOptions;
import com.lipaluma.field.validator.ValidatorFactory;
import com.lipaluma.xml.mapping.XmlFieldMapping;

/**
 * MapColumn that maps a String.
 * 
 * @author Mario
 */
public class StringFieldMapper extends AbstractStandardSingleFieldMapper {

	public StringFieldMapper() {}
	/**
	 * Field Mapper used to map a String
	 * @param mapping information of mapping
	 */
	public StringFieldMapper(MappingInfo mapping) {
		super(mapping);
	}

	@Override
	protected void init(MappingOptions mappingOptions) {}
	
	@Override
	public ChainValidator createChainValidator(Context context, Field field) {
		ValidationBasicOptions validationOptions = ValidationBasicOptions.builder().byAnnotation(field.getAnnotation(Validate.class)).build();
		return ValidatorFactory.createNewChainValidator(context, field, validationOptions);
	}

	@Override
	public ChainValidator createChainValidator(Context context, Field field, XmlFieldMapping mapping) {
		return ValidatorFactory.createNewChainValidator(context, field, mapping);
	}

	@Override
	protected Object parseExtractedValue(String value) {
		return value;
	}
	
	@Override
	protected Object formatValueToWriteOnRow(Object value) {
		return value;
	}
}
